import request from "@/utils/request";

//请求角色列表
export const reqRoleList = (page = 1, limit = 5, roleName = "") => {
  return request.get(`/acl/role/${page}/${limit}`, {
    params: {
      roleName,
    },
  });
};

//添加角色&编辑角色
export const reqAddOrEditRole = (formData) => {
  if (formData.id) {
    return request.put(`/acl/role/update`, formData);
  } else {
    return request.post(`/acl/role/save`, formData);
  }
};

//单个删除角色
export const reqDelSingleRole = (id) => {
  return request.delete(`/acl/role/remove/${id}`);
};

//批量删除角色
export const reqBatchDelRole = (idList) => {
  return request.post(`/acl/role/batchRemove`, idList);
};

//根据角色id获取角色权限列表
export const reqMenuInfoByRole = (roleId) => {
  return request.get(`/acl/permission/toAssign/${roleId}`);
};

//给角色分配权限
export const reqRoleForAuth = ({ roleId, permissionId }) => {
  return request.post(`/acl/permission/doAssign`, null, {
    params: {
      roleId,
      permissionId,
    },
  });
};

//修改角色
export const reqEditRole = (formData) => {
  return request.put(`/acl/role/update`, formData);
};
